package com.exigenservices.practice.roadcompanion.web;

import com.exigenservices.practice.roadcompanion.server.dto.AuthDTO;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import javax.servlet.http.HttpServletRequest;
//TODO rename
public class pageEnter extends SimpleFormController  {

    @Override
    protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {

        return new AuthDTO();
    }
    /*
    @Override
    protected Map referenceData(HttpServletRequest httpServletRequest) throws Exception {
        Map<String, Object> attributes = new HashMap<String, Object>(1);
        return attributes;
    }       */

    @Override
    protected ModelAndView onSubmit(Object command, BindException e) throws Exception {
        AuthDTO dto = (AuthDTO) command;
        ModelAndView mv = new ModelAndView("redirect:profile.htm");

        mv.addObject("login", dto.getLogin());
        mv.addObject("pass", dto.getPass());

        return mv;
    }
}
